package com.cskaoyan.tcp.edition2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/*
        客户端
 */
public class Client {

    public static void main(String[] args) throws IOException {
        // 创建Socket对象
        Socket socket = new Socket("localhost", 9090);

        // 获取流
        OutputStream out = socket.getOutputStream();
        String data = "hello, server";
        // 发送数据
        out.write(data.getBytes());


        // 接收响应
        InputStream in = socket.getInputStream();
        byte[] buf = new byte[1024];
        int count = in.read(buf);

        // 解析读取到的数据
        String s = new String(buf, 0, count);
        System.out.println(s);

        socket.close();

    }
}
